package com.dtz.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.dtz.rabbitmq.constant.RabbitConstant;


/**
 * 消息队列配置，路由模式
 * @author 陶志胜
 *
 */
@Configuration
public class TopicConfiguration {
	

	/**
	 * 定义交换机
	 * @return
	 */
	@Bean
	public TopicExchange topicExchange() {
		return new TopicExchange(RabbitConstant.TOPIC_ORDER_EXCHANGE, true, false, null);
	}
	
	/**
	 * 定义消息队列
	 * @return
	 */
	@Bean
	public Queue topicEmailQueue() {
		return new Queue(RabbitConstant.TOPIC_EMAIL_QUEUE, true);
	}
	
	@Bean
	public Queue topicSmsQueue() {
		return new Queue(RabbitConstant.TOPIC_SMS_QUEUE, true);
	}
	
	@Bean
	public Queue topicDuanxinQueue() {
		return new Queue(RabbitConstant.TOPIC_DUANXIN_QUEUE, true);
	}
	
	/**
	 * 将消息队列与交换机绑定
	 * @return
	 */
	@Bean
	public Binding topicEmailBinding() {
		return BindingBuilder.bind(topicEmailQueue()).to(topicExchange()).with(RabbitConstant.EMAIL_TOPIC_ROUTING_KEY);
	}
	
	@Bean
	public Binding topicSmsBinding() {
		return BindingBuilder.bind(topicSmsQueue()).to(topicExchange()).with(RabbitConstant.SMS_TOPIC_ROUTING_KEY);
	}
	
	@Bean
	public Binding topicDuanxinBinding() {
		return BindingBuilder.bind(topicDuanxinQueue()).to(topicExchange()).with(RabbitConstant.DUANXIN_TOPIC_ROUTING_KEY);
	}
	
}
